package com.example.sbbsec.quartz.schedule.impl;


import com.example.sbbsec.quartz.entity.schedule.cron.CronJob;
import com.example.sbbsec.quartz.schedule.BaseJobService;
import com.example.sbbsec.quartz.util.QuartzUtil;
import org.quartz.Trigger;
import org.springframework.stereotype.Service;

import static com.google.common.base.Strings.isNullOrEmpty;

/**
 * 定时任务接口服务 实现类
 *
 * @author lowe.yang
 * @date 2019-01-25 16:43
 */
@Service("cronJobService")
public class CronJobServiceImpl extends BaseJobService<CronJob> {

    @Override
    protected Trigger buildTrigger(CronJob job) {
        return QuartzUtil.buildCronTrigger(job);
    }

    @Override
    protected void checkJob(CronJob job) {
        super.checkJob(job);

        if (isNullOrEmpty(job.getCronExpression())) {
            throw new IllegalArgumentException("cronExpression can not be empty");
        }
    }
}

